package com.ejemplosdk;


import java.io.Serializable;

import mobilefeel.sdk.MobileFeelActivity;

import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.Toast;

public class EjemploActivity extends MobileFeelActivity {

	private PowerManager.WakeLock wakeLock;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.main);
		
        this.findViewById(R.id.conectar).setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View arg0) {
				EditText entry = (EditText) EjemploActivity.this.findViewById(R.id.entry);
				String ip = (entry.getText().toString()).split(":")[0];
				String puerto = (entry.getText().toString()).split(":")[1];
				connect(ip, Integer.parseInt(puerto));
				Toast.makeText(EjemploActivity.this,"Conectando... "+entry.getText().toString(),Toast.LENGTH_SHORT).show();
			}});

        this.findViewById(R.id.desconectar).setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View arg0) {
				EjemploActivity.this.disconnect();
				Toast.makeText(EjemploActivity.this,"Desconectando...",Toast.LENGTH_SHORT).show();
			}});        
		
        
        PowerManager powerManager= (PowerManager) getSystemService(Context.POWER_SERVICE);
        wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "Tesis");
        wakeLock.acquire();  
	}
	
	
	@Override
    protected void onResume() {
        super.onResume();
        wakeLock.acquire();
	}

	@Override
    protected void onPause() {
        super.onPause();
        wakeLock.release();
    }
	
    protected void onDestroy() {
        super.onDestroy();
        wakeLock.release();
    }
    
    @Override
    protected void onConnectionEstablished() {
    	Log.i("Tesis", "Connection established!");
    	this.registerView(this.findViewById(R.id.TouchEvent), "TouchEvent");
    }
    
    @Override
    protected void onConnectionFailed(String reason) {
    	Log.e("Tesis", reason);
    }
    
    @Override
    protected void onCustomDataReceived(String text, Serializable object) {
    	if(text.equals("prueba"))
    		Log.i("Tesis", (String) object);
    		
    	
    }
}
